package com.fh.service.impl;

import com.fh.entity.po.User;
import com.fh.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@Service
public class LoginServiceImpl implements com.fh.service.LoginService {
    @Autowired
    private HttpServletRequest request;
    @Resource
    private UserMapper userMapper;
    @Override
    public Integer userLogin(String userName, String password) {
        User userByName = userMapper.getUserByName(userName);
        if (userByName==null){
            throw new RuntimeException("用户名不存在");
        }
        if (!com.fh.utils.MD5Util.encoder(com.fh.utils.MD5Util.encoder(password)+userName).equals(userByName.getPassword())){
            throw new RuntimeException("密码错误");
        }
        HttpSession session = request.getSession();
        session.setAttribute("userInfo",userByName);
        return 0;
    }
}
